<template>
  <transition name="bounce">
    <div  :class="{'success':success,
                   'in-fo':info,
                   'waring':waring}"
         v-if="cancel" class="message_cancel">
     <slot></slot>
    </div>
  </transition>
</template>

<script>
    export default {
      name: "message",
      data(){
        return{
          cancel:false,
          success:false,
          info:false,
          waring:false
        }
      },
      props:{
        message:{
          type:Boolean,
          default:false
        },
        theme:{
          type:Number,
          default:2
        },
      },
      watch:{
        message(){
          this.theme === 0&&(this.info = true);
          this.theme === 1&&(this.success = true);
          this.theme === 2&&(this.waring = true);
          this.message&&this.cancelTime();
        }
      },
      methods:{
        cancelTime(){
          this.cancel = true;
          let _this = this;
          setTimeout(()=>{
            _this.cancel = false;
            _this.$emit('update:message',false);
          },1500)
        },
      }
    }
</script>

<style scoped>
  .success{
    color:#67c23a;
    background: #f0f9eb;
    border: 1px solid #e1f3d8
  }
  .waring{
    background: #fffaef;
    color: #e6a23c;
    border:  1px solid #fbeedb;
  }
  .in-fo{
    background: #fef0f0;
    color: #f56c6c;
    border:  1px solid #fde2e2;
  }
  .message_cancel{
    width: 70%;
    height: 80px;
    line-height: 80px;
    box-sizing: border-box;
    border-radius: 10px;
    position: absolute;
    left: 50%;
    top:10%;
    text-align: center;
    font-size: 30px;
    transform: translate(-50%,-50%);
    z-index: 9999;
  }
  .bounce-enter{
    opacity: 0;
    margin-top: -30vh;
  }
  .bounce-enter-active{
    transition: all .5s ease;
  }
  .bounce-leave-active{
    transition: all .5s ease;
  }
  .bounce-leave-to{
    opacity: 0;
    margin-top: -30vh;
  }
</style>
